complete build logic, add rebuild functionality