Refactoring, improved formatting