based on coding by whistleonwild