small rearrangement of mainscreen code to try and fix bugs