separated out some logic into some private methods