Avoid stopping the replicationManager too soon

The replication manager should still be closed even later but I am trying to be conservative with the changes, by moving it further down first.