Refactored for consistent style. More refactoring still remains to be done