Implement statejoin & fix related bugs