refactored and handling time conversion