Optimize command filtering