Refactoring and code cleanup

Better argument and config parsing
Slightly cleaner code base
A few fixes, include Windows compatibility