main function /w tests