Added some memory management and made sure it wouldn't go below MIN_SIZE