Additional test coverage; various bug fixes due to increased test coverage