fix exit status and add bounds checks to input