Removed code duplication and moved all code for parsing events to an external library.

Signed-off-by: Ah-Lun Tang <tang@ahlun.be>