Add loadingbar and fix bug with close of window