Did some much needed refactoring