Refact. Add logging.