added macros, conditionals. fixed some errors