Added some safety checks for input