Extraced Active Record logic