refactor losts of code