Refactoring, cleanups