Slight refactoring; some issue with sqlite3 and list slicing.