A lot of fixes, database work, memory leaks