moved ref logic to models