heap not working properly