minor refactoring (moving logic out of view)