Very sloppy work getting everything together... but I'm running out of time. Might not be an efficient implementation or a good design, but if it works I'll be content.