Move logic to model and simplify.
fixed conflicts
Merge branch 'tuvistavie-master'