optimized code. removed each step dom manupulation