Added isNaN check in expand/collapse