Finally got the logic correct.