There was an issue with the order at which to_format variable was set.