Added the ability to register interrupt handlers, code cleanup, added more checks