Fix various PHP Notices and JS errors