Added memory cleanup functions, class for easier passing of objects and cleanup loops