extensive bug fixes