changed regex and optimized filter code