code refactor. simplified code