Add preload hook support, and minor cleanups