Function acting funny - C#