Basename fixes

This pull request tries to achieve a consistent behaviour of keySetBaseName and keyAddBaseName. However, as can be seen in the latest commit, it would break a lot of existing code