Added limit checks to motor control code