have you tried blitting the incremental steps? it would help to blit the mask to the screen to see if it came out ok. Then try blitting the results of each step to the screen to see if they are what you expect. Figure out where it went wrong first