changed api from direct object editing to return value in order to clean array at the beginning