refactored list function