move code from helper to model