Fixed bug in dom element referencing