refactored and tweaked some times