Refactoring this mess of code
Refactor #1