Update mode.cs

this probably works; need more test cases