extracting logic to controller