credit StackOverflow user that wrote the original C# code