fix bug in getEntropy() plus some refactoring