various bugfixes, code style and docblock improvements