Attempted fix for #117

Based on @markcarver's comment and @alexpott's reported JS error.