rewritten preprocessing