made changes after first review, replaced macros with functions