Remove duplicated code in map controller