removed innerHTML, code modularized and optimized