refactered code