Refactored just a little to make it cleaner and extended a test