fixing flatMap to be right associated