modified textbook functions