clean up Reference and add tests for it