Moved functionality from View to Controller