fixed memory exceptions

Maybe?