First attempt ; passes unit tests