Fixed small charref handling problem and added tests