Code cleanup

Fixed some logic errors in the script loader, and fixed PHP 5.2 support.