Database almost works, strange bugs