issue #1196 and some optimizations