More or less completed test coverage. Fixed found issues