cost function is increasing somehow. need a fix