refactared code