Address issue #1064 and implement unit tests for it