Some bugs fixed