Fixed a merge error. Some of the code needs to be rewritten.