changed: better factorization and build system