Memory management fixes

Fixed memory handling and allocation during preference parsing