Pull out compile logic to function