main.c cleanup, tests fixed