Some refactoring.. Still a little broke