fixed an edge case in problem 3