Numerous bug fixes and modifications.