Added figures and generalized some functions