Refactoring, cleaning up code