beautifying the code first....and a little refactoring