       data.layers.each (layer, layerIndex) ->
         return unless layer.name.match /entities/i
 
-        layer.tiles.each (row, y) ->
+        layer.tiles?.each (row, y) ->
           row.each (tileIndex, x) ->
             if spriteLookup[tileIndex]
               entityData = $.extend(

              , data.tileset[tileIndex]?.properties)

              entityCallback(entityData)

    loadEntities()      


( ->
  Map = (data, entityCallback) ->
    tileHeight = data.tileHeight
    tileWidth = data.tileWidth
