Refactoring code in MTL, fixing some compiler errors