Refactored a lot of excess code