             Log.error("Error converting strings to data for multipart parsing")
             return nil
         }
-        
-        enum ParseState {
-            case preamble, body
-        }
+
         var state = ParseState.preamble
         var parts: [Part] = []
         var currentPart = Part()

            switch(state) {
            case .preamble where bodyLine.hasPrefix(boundaryData), .body where bodyLine.hasPrefix(boundaryData):
                // boundary found
                if partData.length > 0 {
                    if let parser = getParsingFunction(contentType: currentPart.type), let parsedBody = parser(partData) {
                        currentPart.body = parsedBody
                    } else {
                        currentPart.body = .raw(partData)
                    }
                    parts.append(currentPart)
                }
                currentPart = Part()
                partData = NSMutableData()
                if bodyLine.hasPrefix(endBoundaryData) {
                    // end boundary found, end of parsing
                    return .multipart(parts)
                }
                state = .body
            case .preamble:
                // discard preamble text
                break

        }
        return nil
    }

    private class func handleBoundary(partData: inout NSMutableData,
                                      currentPart: inout Part, parts: inout [Part]) -> ParseState {
        if partData.length > 0 {
            if let parser = getParsingFunction(contentType: currentPart.type),
                let parsedBody = parser(partData) {
                currentPart.body = parsedBody
            } else {
                currentPart.body = .raw(partData)
            }
            parts.append(currentPart)
        }
        currentPart = Part()
        partData = NSMutableData()
        return .body
    }

    private class func divideDataByNewLines(data: NSData, newLineData: NSData) -> [NSData] {
        var dataLines = [NSData]()
        var lineStart = 0
