Fix program loading and switch calculating to work generally

Some logic was hard-coded for the prototype demonstration. It should work for all cases now.