Bug fixes in the interrupt handling

* bug fixes in the handling of PxIV and IFG
* fixed DEBUG to be set when loglevel is set to DEBUG
* some other bug fixes and code cleanup