modified code to have better design