tidied main a bit