Cleaned up the cleanup function