updated functions, bug fixes