Refactor friendship code, write more tests