code cleanup and timing changes