Fixed null pointer error and added some timing output