refactory some code