Refactoring and minor optimizations of getKey
Add a comment to explain need for rabs
Fix some issues and optimize a bit search