new version of james' code