Limit switch not recognised and Z has mind of own

If you know how to use the serial monitor then bring it up. If not, read through this and see if that gets you going.