refactoring code
added addfirst funct