Fix Issues #103 - Shouldn't call sync.end() when there is an error

Closes #103