Crappy code I wrote at home. Cannot test it from here.