Fixed a bug that would cause an exception in some cases.