improve code coverage and fix some bugs

i had another go over the code and cleaned up more stuff.