various bugs fixed