removed redundant checks, fixed a lot of stuff
improved test coverage