Refactoring the montelight codebase