This code is tested and works. The original working code was lost, but this does the job. No known bugs, however I believe the naming for the limit switches is backward. Limit switches (and everything else) are working.