minor
Moved fuctions between files
moved macros to a separate file
minor