Added "debouncing" implementation for input pins. Various fixes and
code style cleanup.