fix bug -- failure to wait for document on ready