Actually working code! (I hope)