fix and modify
add reduce function