fixed minor bugs, added php docs to all functions