Clean up code style and add missing PHPdoc