 					# clean takeover
 					beacon.remove 'inRange', client
 					removed = client
-				log 'removed=', removed
+				#log 'removed=', removed
 				# ========== Handle changes for inRange players ==========
 				# Determine members per team
 				teamMembers = (0 for team in [0..5])
 				beacon.iterate 'inRange', (player) !->
-					if (not removed?) or player.key() isnt removed
+					if parseInt(player.key()) != parseInt(removed)
 						team = getTeamOfUser(player.key())
 						teamMembers[team] = teamMembers[team]+1
 				#log 'teamMembers count: ', teamMembers	


# Checkin location for capturing a beacon		
exports.client_checkinLocation = (client, location) ->
	if Db.shared.get 'gameState' is not 1
		log 'Client ', client, ' (', Plugin.userName(client), ') tried to capture beacon while game is not running!'
	else
		log 'checkinLocation() client: ', client, ', location: lat=', location.lat, ', lng=', location.lng


exports.client_deleteBeacon = (client, location) ->	
	#Finding the right beacon
	if Db.shared.peek('gameState') isnt 0
		log Plugin.userName(client), ' (id=', client, ') tried to delete a beacon while game is not in setup phase!'
	else
		Db.shared.iterate 'game', 'beacons', (beacon) !->
			if beacon.peek('location', 'lat') == location.lat and beacon.peek('location', 'lng') == location.lng
				log 'Deleted beacon: key='+beacon.key()+', lat=', location.lat, ', lng=', location.lng
				Db.shared.remove 'game', 'beacons', beacon.key()
	
