First major commit, refactored out some major flaws