refactor out size function