Add doc to function and remove dead code