reduce overuse of dom and optimize code