refactor logic from helper to model