create some function to refactor
reindent code
refactor a little bit