rewrote all the code