Bug fix for setting keys