added optional layer filtering function