Refactor some code, CS and phpdoc