fixed missing esac and improved output