added macros, removed all magic numbers