resurrected testing function and moved main to test