Updated to properly handle OR predicate (Thanks to @tsvijayan)