refactor pseudocode