Completely rewrote code to work with querystrings.