Code cleanup, log error via amabuce feedback and write_log functions