fixed error throwing
added tests