Added trigram support and tidy up