Optimize Makefile. Add Makefile for tests. Fix test build