refactored argument checking code