refactory a little bit