rearrange
added case where key is not found