UPDATED CODE: reflects current functioning local copy