The cleaned up code is tested, and appears to be alright