Optimized code
Fixed #168