completed the algorithm in normalize.py