Some cleanup, refactoring