Optimized memory usage and the methods now handle internal exceptions.