new code with a few changes