Issue #27 resolution and general workaround for "garbage after JSON..." error

Adding modifications stemming from issue #27 and also proposing a generic workaround for "garbage after JSON..." specific errors.