fix computing valid locality levels
add unit test and fix bug