Another attempt at fixing exit issue