improved code with enumerate function r.46-51