Remove unused code, add better documentation