ugly code, but now working for some minutes without crashing