fixed some bugs and it finally runs without errors as a monkey plugin