switched to an OO system client side, rewrote to make it much nicer to understand and upgrade