Code cleanup and php docs