implemented sequence using flatmap