Major rewrite of update script.

Also added update SGID functionality.