rebuild the logic