Fixed bug in distinct scoping