The system now works but requires some serious refactoring.