Removed dead code, added check for map size