Move some costs code to contorller. Change tid to type in view.