moved all logic to model