[refactor] moved some function to end of file