Fixed error occurring on exit