Refactored to reduce fugly arguments parsing 

Thanks to @allouis for the feedback.