Refacting of whole master script