Organize code and improve build system