Almost got database working correctly