Added better type checking.