Major bug fix, some other modifications.