latest changes with some error checking