Cleaned up command handling significantly