Handling rules.length is undefined error

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