implemented unit-test for error messages and error checking
fixed potential memory-leaks