Fixed bugs and php errors