I think I got it working now. Added some comments to make some sense. I accidentally auto formatted the entire file. Force of habit.