Added flatMap and stuff that uses it