You should also be checking out debouncing.
This is very important for getting reliable results from switches.