Fixes and some more refactoring.

+ PHPDocs