several bug fixes