refactored code for lists; added tests