improve refs handling