Updated the callback to the client application snippet to care
properly of edge cases.