Refactor solution and add second solution using slice method