adding more meaningful messages and doing some bug checking