Updating code to conform to new document API