moved some duplicated code into models