Updated code after testing in the lab