Refactored to match function map in wiki

Farily big update - it should now be ready to test.