Bug fixing (still a mem leak somewhere)