Added more test coverage, test macros, and refactored where necessary.