Making progress.. will still need to rewrite some of this though.