Modifications in the initial post; Added code for first two steps