Moved most of the logic in the compiler plugin