Finished autodetection

Must be optimized and universalized!!!!