Ruby style cleanup and refactoring