Fix #16. Move the check inside the previous if block to avoid 'latest_timestamp to be undefined'.
manual merge