fixed many bugs, improve the code and update the events module