Added type check for safety