Simple script complete but major factoring needed