Refactored malloc for strings to its own function.