Made objects clear more handlers on deletion, also scramble some methods and all database access wrappers to avoid an object memory instance being accessed after it has been deleted. See #509.
Fixed code to pass unittests. Change script's is_valid method to correctly catch if it is checked on an object which is already deleted, as per #509.