somewhat broken code, but toward the end of night