Refactor relation into classes