made some changes after reading the comments