Implemented Feed forward and cost function