Cleanup + minor refactoring