Increasing test coverage and fixing bugs found while writing tests

Sorry, got carried away. :smiling_imp: