refacor some code