Some refactoring, updated the manuals and docs