Merged in missing parts from mmind00's commit.