Updated command filtering with optional command type parameter.