Updated code for exit bug