added function prototypes. rearranged code.