implemented flatMap, and reimplemented map using flatMap