Added function to remove key from log to reduce duplicate code