Fixed build script and reorganized code