 
   # Returns a list of keys of this
   keys: ->
-    return Object.keys(@value)
+    keys = new List Object.keys(@value)
+    return keys
 
   # Returns the popped value at key if key exists. 
   # Else returns `d` if default `d` exists
   # Else raises `KeyError`
   pop: (key, d) ->
-    if key in @keys()
+    keys = @keys()
+    if keys.__contains__(key)
       val = @value[key]
       delete @value[key]
       return val
     else if d?
       return d
     else
-      (new KeyError "#{key}").raise()
+      raise new KeyError "#{key}"
 
   # Pops random item from this and returns a 2-tuple
   popitem: ->
-    if @__len__() == 0
-      (new KeyError "popitem(): dictionary is empty").raise()
-    randomKey = @keys[0]
-    randomValue = @__getitem__(randomKey)
-    return new Tuple([randomKey, randomValue])
+    if @__len__().value == 0
+      raise new KeyError "popitem(): dictionary is empty"
+    keys = @keys()
+    randomKey = keys.__getitem__ 0
+    randomValue = @__getitem__ randomKey
+    return new Tuple [randomKey, randomValue]
 
   setdefault: (key, d) ->
-    if key not in @keys()
-      @__setitem__(key, d)
+    if key not in @keys().value
+      @__setitem__ key, d
     return @value[key]
 
   # **Unimplemented**

    return new DictionaryKeyIterator(@)

  __le__: (dict) ->
    return @__lt__(dict) or @__eq__(dict)

  __len__: ->
    return Object.keys(Object(@value)).length

  # First checks length of dictionary, then compares sorted keys and their associated values
  __lt__: (dict) ->
    if @__len__() < dict.__len__()
      return true
    else if @__len__() > dict.__len__()
      return false
    else
      keys = Object.keys(@value).sort()
      otherKeys = Object.keys(dict.value).sort()
      for key,i in keys
        if key >= otherKeys[i]
          return false
        val = @__getitem__(key)
        otherVal = @__getitem__(otherKeys[i])
        if val >= otherVal
          return false
      return true

  __ne__: (dict) ->
    return not @__eq__(dict)

  # **Unimplemented**
  __repr__: ->

    set = new Set(keys)
    otherSet = new Set(otherKeys)
    if set.__ne__(otherSet) #if keys are different, not equal
      return new Bool false
    for key in keys
      val = @__getitem__(key)
      otherVal = dict.__getitem__(key)
      if val != otherVal #if values differ, not equal. Unsure if this should be __ne__
        return new Bool false
    return new Bool true
    
  __ge__: (dict) ->
    return new Bool @__gt__(dict) or @__eq__(dict)

  __getattribute__: (attr) ->

