finalized code

program works as directred