Refactored open/close list function. Condensed into global function for multiple usage