Changed code following comments