Code edited for clarity