major clean up, leaving one function