refactor extraction code a bit, more cleanly handle html case