Issue #516 bug fixing