Fixed bugs in hueristic functions

.