Program flow should make more sense. Added image'