updating to Bryan's code