added preliminary stage 2 functions. Made necessary changes to stage 1
functions.