Rewrote all code to fit specification