Updates database properly