error handler added 

all function error handling added