[aot] Refactor the code a bit.