The code was very janky, but it worked