Refatoring the code