Fixed the direction when unrolling of brackets and added graceful exception handling at exit.