I have rewritten the stepwise descriptions to clarify how functions are called and the semantics needed to be implemenetd in the functions.Hope it is clearer now.