Fixes a bug that causes dispose to be triggered multiple times