added three functions to help
fixed some errors