Updated code with error messages; simplified test application