Edited for code clarity