Updated code for proper javascript error detection and resource loading issues .