refact some code