added james' code