Refactor command handling into Command class