Modified/reorganized the code, added solid angle in background events calculation. Still crashes.