added type checks to most functinos