Logic error - C#