Fixed logic of callback and added missing comments.