refactoring to use composite keys and unit tests