Modified to use sqlite instead of text files