Improve mask creation

Signed-off-by: Ilya Nelkenbaum <ilya@nelkenbaum.com>