Swap gsub for match
Improved permission checks w/ reduced queries
Improved WHERE with OR/AND support
Final gsub => match