[fix] fixed removal of a heap element

Error was caused by late element removal