Better handling of dispose()