code refacotred