Renamed some functions to give them better names and converted more macros into functions or constants