Finally working code. yay.