Refactored all the crap