Making my functions more generic - C#