working base. cleaning up and documenting code.