code refactered