better solution for this problem