Refactor some areas to simplify program.