A little refoctoring and test added