fix #12 and some performance optimizations