improved js printing code
updated version