Refactored if/else for adding new items at beg or end