Improve orientation change handling

Addresses #10. This commit also includes some unrelated code restructuring.