pseudocode improved