Allow saving of user IDs

Also, large amount of code cleanup.