wip
Cleanup and refactoring