Improved code for autoExpand and loadDate to keep the current scroll position