Fix some stuttering caused by garbage collection, add some dispose functions, some refactoring