code adapted for maps