Refactor Main a bit