reorgainzing code for timing