Added phpdoc annotations, fixed bugs