Possibly fixed writeToDB bug