moved gc into function