Added some extra clean-up logic