Took a pass at cleaning up the code and adding documentation

Signed-off-by: Sean Flynn <ecthelisean@gmail.com>