I have some similar trouble too in that I sometimes naturally grind the rail and come out switch without even meaning to.
The solution to this (hypothetically, I still don't have it full down), keep your head looking directly at the end of the rail / box, and yeah, like other people have said, grind up the inside edge of your leading ski to stop you turning a big
As far as the falling forwards and backwards part, just gotta keep your shoulders above your feet.
Also, something that really helped me learn rails, when you come up to a rail (assuming its not a rail you hop onto from the side), approach the rail and have it perfectly centered between your skis (slightly wider stance when you hop on the rail), but yeah, the rail perfectly in front of you between ur legs. then hop on and turn 90'
Maybe that was confusing but hopefuly it helped
all.mountain