Cleanup and refactor