Factor out class loading code