Classes for context and template, changes in the algorithm but the damn thing still doesn't work