improved code clarity, added max value