Updated region growing code