Cleaned up command matching code