Working solution

Seems to be working, yay!