a few tidyups
simplified replace_entrypoint