factor out random