Fixed major issues and refactored some more