Added a test, made things dryer and nicer with helper methods.