Added more type checking