refactor code to change location of callback inside of render