Fixed some bugs in the fill/drain code and also compacted it quite a bit.