Major refactor, untested

Signed-off-by: Brandyn A. White <bwhite@dappervision.com>