Refactored code. This should be ready to commit. Not yet tested
Working code. All tests passed. Ready for pulse.