updated script from kensykora/feature/issue-83 + try/catch and LogWrite