a lot of cleanup and fixes for orientation