rebuild

re-rewrite the logic