Fixed masking and resizing

Should also benefit performance