Get rid of what you have now and start with this.

Arduino playground - Keypad Library

this is the keypad code for the arduino board.