Changed the code on more friendly and smart