fix code loading detection and handle flat binary properly