removed a lot of duplicate code, changed the replace jquery call to use
this.setElement instead