Fixed some mistake in the error handling functions.
added error code support