Command refactor

I've done a lot of work refactoring the way commands are implemented. I have not done any testing, however.