Updated to match stack overflow code