Add ifs to stop exceptions