Added some technical documentation and some minor refactoring.