added automatic canvas resizing