refactored loop inside of addNumber function