solved problem 1.6.3, still need to complete the edge cases