cleaning unused or only used once code

There were a lot of functions that had ambition, but are either not referenced at all, or only referenced once.  removed unused code or duplicated code; moved code only used once to where it's used