Fixed issues, documented and tested

Ready for review :)