Resolved type issue in flatMap and map