Implemented below mentioned points :

1. Optimized 4th and 5th point.
2. Make the code DOM independent.