refactor pynhost script