Style and bug fixes

Some changes to php files.