fixed looping issue by using underscore method
refactor gCost function and shorten run method