borrowed lots of code from pyfibot. feel dirty now.