implement helper function.
Overall logic now work.