duration-calc and cleanup of code