added autoload

Added autoload and backported Ryan Davis' updates.