clean up the main func a bit