Updated with code from YHack