Fix some bugs/errors and added phpDoc