Simplify and add masked operations (thanks Steve Thomas)