refacto code for latter reuse and more resilient code