The code you have does something. You haven't told us what it ACTUALLY does. It's nearly impossible to help you make the code do what you want without knowing what it actually does, and how that differs from what you want.
Since you haven't declared the mode of the limit switch pins, we can assume that you are not using the internal pullup resistors (though why you aren't is a mystery). So, we can conclude that you need external resistors. You haven't said how the switches are actually wired.