Fix bug in BY implementation