Bug fixes

Fixed a ton of PHP bugs