extracted some things in functions