Add program loading

Also fix several bugs