Mostly done with debugging and refactoring ahead