refactored code to use Vec class