Fixes some memory and performance issue