FlatMap Task clean-up

Clean up of task body. Also, added handling of potential 'null' return
from Path.GetDirectoryName.