Use IsInteger for the integer check
Fix missing assignment
Reduce nesting