Moved code from js to view