a scratch code for learning IM working procedure