Refactoring to make the detection more robust

Also, line endings were changed to unix style
Simplify modman file