a few syntax changes and safer code