Divide code into inputs and sinks for #504 and #490.
Progress on tests for #490. Very messy, and will clean up in #489.