added begin rescue end and error logging