Moved setting to arguments
Refactored the entire thing, more robust and better detection.