Lots of code. Functions currently, but needs some cleanup.