Overhaul

Complete reformatting and refactoring of the existing code.