Factor out floodFill to multiple functions.

Fixes #8.