Deleted largely redundant and ill-designed section of code, created psuedo-code