Added pseudocode and code