Adding error logging