fix reduce fn
add reduce tests