Changed code to be simpler