changed to use element instead of document