added function checking and some minor fixes