complete with comments and passes unit tests