Major code cleanup. Added code to match parameters automatically. Fixed some unit tests.