Fixed some additional bugs introduced in the latest changes.
Additional code cleanup.