refactoring script complete, needs testing and implementing macros correctly