Refactored main class, only initiate things when necessary.