refactring the code