Extract masks and length