Added more exceptions, moved reply parsing into its own method,
use with statement for locking.