Refactoring and added timing events for analysis purposes