Tidy up code, move general queries to trigger based on regex.