General bug fix

General crash and bug fixes, also added framework for further random
events.