added proper error logging