Refactored Compiling Code to use Linq