fixed some memory issues and stuff