Refactored main a bit