Refactoring and cleaning up code with help from Señor Furnes.