fixed input error checking and implicit typecasting