More code clean up, better documentation