remove exit in a middle; code clean up