adds TypeError and removes redundant code