     
     //F.IX needs mathematical basis
     mutating func correctBucketCount() throws {
-        print("correcting bucket count?")
-        let max = table.max { $0.count > $1.count }.count
-        var tc = table.count >> 1
-        if tc < 3 {
-            print("did end because tc * 2 < 5: " + table.count)
-            return
-        }
-        if max > count / tc {
-            print("increasing bucket count!")
-            try changeBucketCount(tc)
-        }
-        print("max: " + max + ", table.count * 2: " + tc)
-
-        let min = table.max { $0.count < $1.count }.count
-        tc = (table.count << 1)
-        if tc < 5 {
-            print("did end because tc / 2 < 3: " + table.count)
-            return
-        }
-        if min < count / tc {
-            print("decreasing bucket count!")
-            try changeBucketCount(tc)
-            return
-        }
-        print("min: " + min + ", table.count: " + table.count)
-    }
-    
-    func hash(key: Element) throws -> Int {
-        var h = (hashFunction(key) % table.count)
-        while h < 0 {
-            h += table.count
-        }
-        h = h % table.count
-        if 0 < h || h >= count {
-            throw HashTableError.BadHashFunction
-        }
-        return h
+        print("tries correction")
+        var quotient = (count / table.count) >> 4
+        while quotient > 0 {
+            try changeBucketCount(table.count << 1)
+            quotient = (count / table.count) >> 0x10
+        }
+    }
+    
+    func hash(key: K) throws -> Int {
+        return ((hashFunction(key) + table.count) % table.count)
     }
     
     internal mutating func changeBucketCount(buckets: Int) throws {
         try changeBucketCount(buckets, f: hashFunction)
     }
     
-    internal mutating func changeBucketCount(buckets: Int, f: Element -> Int) throws {
+    internal mutating func changeBucketCount(buckets: Int, f: K -> Int) throws {
         let oldHash = self.hashFunction
         let oldTable = self.table
         do {
-            let newHash = f
-            self.hashFunction = newHash
-            self.table = [[Element]](count: buckets, repeatedValue: [])
+            self.hashFunction = f
+            self.table = [[(key: K, value: V)]](count: buckets, repeatedValue: [])
             for bucket in oldTable {
                 for element in bucket {
                     try insertNoCorrection(element: element)

    }
    
    init(_ buckets : Int) { // convenience init
        self.init(_: buckets, hashFunction: { return $0.hashValue })
    }
    
    init(_ buckets : Int, hashFunction: Element -> Int) {
        table = [[Element]](count: buckets, repeatedValue: [])
        self.hashFunction = hashFunction
    }
    
    //P.ERFORMANCE maybe in parallel or hashing all first in parallel, then appending all?
    mutating func insert(elements: Element...) throws {
        try insert(elements)
    }
    
    //P.ERFORMANCE maybe in parallel or hashing all first in parallel, then appending all?
    mutating func insert(elements: [Element]) throws {
        for v in elements {
            try insertNoCorrection(element: v)
        }
        try correctBucketCount()
    }
    
    //I.DEA private?
    mutating func insertNoCorrection(element new: Element) throws {
        try executeForKey(new) {
            b,i in
                if i != nil { throw HashTableError.InList }
                else        { self.table[b].append(new) }
        }
    }
    
    mutating func overwriteOrAdd(element: Element) throws {
        try executeForKey(element) {
            b, i in
                if i != nil { self.table[b][i!] = element   }
                else        { self.table[b].append(element) }
        }
    }
    
    mutating func executeForKey<T>(key: Element, f: (Int,Int?) throws -> T) throws -> T {
        let h = try hash(key)
        let i = table[h].find { key == $0 }
        return try f(h,i)
    }
    
    mutating func executeForUniqueKey<T>(key: Element, f: (Int,Int?) throws -> T) throws -> T {
        let h = try hash(key)
        let i = try table[h].findUnique { key == $0 }
        return try f(h,i)
    }
    
    mutating func overwrite(element: Element) throws {
        try executeForKey(element) {
            b, i in
                if i != nil { self.table[b][i!] = element    }
                else        { throw HashTableError.NotInList }
        }
    }
    
    mutating func insert(element new: Element) throws {
        try insertNoCorrection(element: new)
        //P.ERFORMANCE useful? maybe saving counter and only testing after 10 insertions...
        try correctBucketCount()
    }
    
    mutating func get(key key: Element) throws -> Element {
        return try executeForKey(key) {
            b, i in
                if i != nil { return self.table[b][i!] }

    
    //T.ODO removeSavely - using findUnique
    
    mutating func remove(key key: K) throws -> (key: K, value: V) {
        return try executeForKey(key) {
            b, i in
                if i != nil { return self.table[b].removeAtIndex(i!) }
