Re-implemented Issue-135 with updated master branch from upstream