moved logic from html into seperate controller