Adding trimming and bad pixel flagging