some changes as mentioned by @pmjones