more bug fixes regarding to error handling