updated code
resolved setElement bug