trim unused functions, add some better comments