Cleaned up code; updated docs.