clean up and add better comments