Refactoring, commenting, cleanup