original working code before doing it for our data