bug fixes and cleanup in extract code