refact main to test