Add oauth to database writes
Clean up some oauth code