fixed endstops

code now tested to work with endstops.