Increasing test coverage and fixing bugs found while writing tests

D'oh!