Moved variable commandArgs closer to its usage because the substring operation was causing an ArgumentOutOfRange exception for me when entering the realm.