perfect program (before refactoring)