Fixed buggy db code; is now usable