Use mapMaybe to discard invalid input