added function defs and comments