optimize selector lexing, fix bugs