Fix key.php bug, improve performance on removekey.php