First try
sort of works except for notisnull - where is m?
tested, debugged, needs cleanup and explanation