commented, added error checking, removed old code