Implementation of GEOS-6618

This implements the changes needed to implement http://jira.codehaus.org/browse/GEOS-6618 and avoids the errors that the previous pull request caused when running tests (all passed)