Improved test suite; fixed error throwing in function