Refactor machine_manage_keys