add checks for empty frames to avoid crashes