Bug fixes in the interrupt handling

* bug fixes in the handling of PxIV and IFG
* fixed DEBUG to be set when setting debug log level
* some other bug fixes and code cleanup