mostly refactor otr code a bit and make some functions more transparent