Fixed few small (but nasty) bugs