refactor to simplify program