Optimized code- Added alloc_ functions.