refactored flatmap test