Pretty much implemented it all. Some refactoring/renaming