Made Reduce stateless, added tests

Signed-off-by: Martin Evans <martindevans@gmail.com>