Fix bugs in mask foreground