moved all logic into models