Refactored the FEM2d code