refactor code and add skip function