Make separate functions for subtracting background and applying masks and gain