Added some tests for repository and fixed couple of bugs