moved code outside of controller need tidy up and test now