server side event, some code clean up and corner case handling