code cleanup + autodetection: