replace tedious code with underscorejs methods

Signed-off-by: railsstudent <con_leung10@yahoo.com>