fix keymapping bugs
fix functions' scopes