added a functional test, and removed a bug in error msg