Handling rules.length is undefined error

added try/catch to ignore error when rules.length is undefined, so
script can continue to execute as page resizes.