remove code duplication from ZMatrix helper functions
move ZWeightedCell to separate compilation unit
add separate class for path weights