outsourced javascript code from canvas page, added log consolethere, made little asthetical changes