fix hash implementation and modify Bresenham algorithm