fixes issue 1985

plus made a pass to jsbeautifier for improved reading
plus fixed an annoying trailing comma that could cause issues with IE >= 8