Refactors compile() and generate_link()