rewrite the program on my own