added some logic and changed the program a little