merged with chris' code