Fixed stupid mistake in error handling, added negative tests.