Moved last  code out of controllers