bugfixes, moved logic from controller to model