Cleanup and using libs instead of macros