Judging: bugfixes and refactoring