Move some logic from views to controller