I have two voices in the right-hand staff. I'm not sure why Lilypond is doing what it is (see freehand circle) but I would like it to stop. The beam should ideally be somewhere near the red line, with the quaver it touches pointing upwards if necessary to avoid clashing.
In order to avoid this problem in the left hand, I tied a chord in only one voice (red arrow). I'm OK with this, because the notes are closer together and it's the easiest way to write it without the note's tail thingies clashing. However, that would worsen the situation in the right hand; the beam would go even higher.
What's the magic Lilypond command to fix all of the problems?