several bugs fixed