added tests and cleaned up main