Reduced duplicate code

Reduce the duplicate code between the Sync and Async methods.
Replaced all Tabs with 2 spaces.