Add tests and fix a missing return statement