logic bugs fixed