Add checking for undefined in buildWhere