fixed error handling method