Changed work from pseduocode