Update extract.js

Ensure that end is called on extraction