function refactor with small test