refactor code
set start flag to control