Update mode.cs

fixing some bugs in the linear approach