added subrouting and numerous other changes