refacto the code