Made this function safer.