Added progress dialog and fixed bugs