complete codes for preprocessing