Code refactoring, split things into different files.
Updated documentation.