Added some checks on inputs