Changed code form last commit to be simpler