Finish writeFilter and writeMask functions