Fixed tests and reduce function