Done some refactoring, still works