version 1 of Miguels code