testing code from stack overflow