Added pseudocode to explain the method