refactored code, fleshed out optimization process... not in functional state yet