Bug fixes and rebuild optimization