many fixes to issue 31
Merge pull request #213 from smogon/f2c0096b1ee401680f3dd505656c791b

many fixes to issue 31