patch 3.1 final

fixed a few bugs