code cleanup.
Fixed double loading bug.
Added loading spinner.