Review logic and make it more robust.