added ifs to avoid double work