refactored evaluation code