added checks to prevent going past start and end steps