Merge for Issue 588

Added unit test and fix for #588