make logical oper typesafe and remove code duplication