made changes suggested by @cwansart