tried to make more robust