Major refactor

Pretty much working :)