Bug fixes and finalization