Completely rewrote all code.