Optimized

Optimized, Fixed bugs and added auto option.