Refactor to use before_compile callbacks