reference to the stackoverflow discussion for the which function