refactory a bit