scratch implementation