FIX: database structure & memory leaks