Tried to idiomize the code