made some changes

added code. reduced some redundancy in one place added some elsewhere