significantly refactored the double_out function for final question 5