Some refactoring. Basic commands work.