refactored print_arr