added further error handling codes.