Refactoring some old PHP code into ASP.NET C#