Added updating  database function.
Fixed legality bugs.