Major bug fixes