refactor code to use more jquery and discard the more native js approach we had.