SQLite working

todo: code cleanup & optimization